var js_base_url = 'http://localhost/our_brgy_new/';
function changepwd() {
    var pwdfirst = $("#pwdfirst").val();
    var pwdsecond = $("#pwdsecond").val();
    if(!(pwdfirst === pwdsecond)) {
        $("#changepwdmsg").html("Password do not match.&nbsp;");
        return false;
    } 
    if(vNotNull(pwdfirst) == "n" || vNotNull(pwdsecond) == "n") {
        $("#changepwdmsg").html("Please fill up both fields.&nbsp;");
        return false;
    }
    $.ajax({
        type:"post",
        url:js_base_url+"index.php/authenticate/changepassword",
        data:"pwd="+pwdfirst,
        success:function(data,textStatus) {
            $("#changepwdmsg").html("Your password has been changed.&nbsp;");
        }
    });
}
function changebrgyinfo() {
    var prov = $("#province_val").val();
    var mun = $("#municipality_val").val();
    var brgy_name = $("#brgy_name").val();
    var zip = $("#zip").val();
    var e_ad = $("#e_ad").val();
    var p_num = $("#p_num").val();
    alert(zip);
    if(vNotNull(brgy_name) == "n") {
        $("#brgy_name").focus();
        $("#changebrgyinfopwdmsg").html("Please fill-up all fields.&nbsp;");
        return false;
    }
    if(vNotNull(mun) == "n" || mun == 0) {
        $("#mun").focus();
        $("#changebrgyinfopwdmsg").html("Please fill-up all fields.&nbsp;");
        return false;
    }
    if(vNotNull(prov) == "n" || prov == 0) {
        $("#prov").focus();
        $("#changebrgyinfopwdmsg").html("Please fill-up all fields.&nbsp;");
        return false;
    }
    if(vNotNull(zip) == "n" || vNum(zip) == "n") {
        $("#zip").focus();
        $("#changebrgyinfopwdmsg").html("Please fill-up all fields.&nbsp;");
        return false;
    }
    if(vNotNull(e_ad) == "n" || vEmail(e_ad) == "n") {
        $("#e_ad").focus();
        $("#changebrgyinfopwdmsg").html("Email address entered is invalid.&nbsp;");
        return false;
    }
    if(vNotNull(p_num) == "n" || vNum(p_num) == "n") {
        $("#p_num").focus();
        $("#changebrgyinfopwdmsg").html("Phone number is invalid.&nbsp;");
        return false;
    }
    $("#changebrgyinfopwdmsg").html("");
    $.ajax({
        type:"post",
        url:js_base_url+"index.php/general/update",
        //datatype:"json",
        data:"brgy_name="+brgy_name+"&mun_id="+mun+"&prov_id="+prov+"&zip="+zip+"&e_ad="+e_ad+"&p_num="+p_num,
        success:function(data,textStatus) {
            $("#changebrgyinfopwdmsg").html("Updates for your barangay information have succeeded.&nbsp;");
        },
        error:function(data,textStatus) {
            $("#changebrgyinfopwdmsg").html("We cannot cater your request this time. Please try again later.&nbsp;");
        }
    });
}
function changebrgydesc() {
    var brgy_desc = $("#brgy_desc").val();
    if(vNotNull(brgy_desc) == "n") {
        $("#changebrgydescmsg").html("Barangay description should not be emtpy.");
        return false;
    }
    $.ajax({
        type:"post",
        url:js_base_url+"index.php/general/changedesc",
        data:"brgy_desc="+brgy_desc,
        success:function(data,textStatus) {
            $("#changebrgydescmsg").html("Barangay description update has succeeded.");
        }
    });
}
